var joi = require('joi');

//规则
var name = joi.string().min(2).max(20).required()//字符，数字英文，必要
var password = joi.string().pattern(/^[\S]{6,12}$/).required()//字符，开头非空， 必须
var phone = joi.string().length(11).pattern(/^[0-9]+$/).required();
var address = joi.string().allow('')
var sex = joi.string().allow('').valid('男', '女')
var age = joi.number().integer().min(18).max(120).allow('')
var avatar = joi.string().dataUri().required()


login_schema = {
    body:{
        name,
        password,
    }
};
register_schema = {
    body:{
        name,
        password,
        phone,
        address,
        sex,
        age,
       
    }
}
//用户更新数据验证
updata_userinfo_schema = {
    body:{
        name,
        phone,
        address,
        sex,
        age,
       
    }
}

//用户密码的重置
updata_psassword_schema = {
    body:{
        oldPwd: password,
        newPwd: joi.not(joi.ref('oldPwd')).concat(password)//新旧密码不一样，规则与password定义的一样
    }
}

//更新头像的
updata_avatar_schama = {
    body:{
        avatar
        
    } 
}
module.exports = { login_schema, register_schema, updata_userinfo_schema, updata_psassword_schema, updata_avatar_schama};

